<template>
  <div>
    <el-dialog
      v-loading="loading"
      class="mt-dialog"
      :title="domain + title"
      :visible.sync="dialogVisible"
      :close-on-press-escape="false"
      top="80px"
      width="1280px"
      @close="close"
    >
      <div>
        <el-form ref="formdata" :model="formdata" label-width="80px">
          <el-form-item label="最低价">
            <el-input v-model="formdata.price_min" type="number" />
          </el-form-item>
          <el-form-item label="最高价">
            <el-input v-model="formdata.price_max" type="number" />
          </el-form-item>
          <el-form-item label="增长价格">
            <el-input v-model="formdata.increace" type="number" />
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-tag type="warning" effect="dark">产品价格大于{{ formdata.price_min }},小于{{ formdata.price_max }}将会被增加{{ formdata.increace }},完成后更新缓存和feed!</el-tag>
        <el-button type="danger" @click="handleModify">确认</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { MoidfyMultiPrice } from '@/api/prestashop/prestashopapi'

export default {
  name: 'Modifymultiprice',
  props: ['pstVisible', 'domain'],
  data() {
    return {
      title: '批量修改价格',
      dialogVisible: false,
      loading: false,
      multiModifyPriceShown: false,
      formdata: {
        'increace': 10,
        'price_min': 0,
        'price_max': 10
      }
    }
  },
  watch: {
    pstVisible(v) {
      this.dialogVisible = v
    }
  },
  methods: {
    handleModify() {
      this.$confirm('真的要批量修改价格，无法恢复' + ', 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true
        MoidfyMultiPrice({
          domain: this.domain,
          increace: parseInt(this.formdata.increace),
          price_min: parseInt(this.formdata.price_min),
          price_max: parseInt(this.formdata.price_max)
        })
          .then(response => {
            this.$notify({
              title: '修改成功,请到网站检查',
              message: response.msg,
              type: 'success',
              duration: 2000
            })
            this.loading = false
          }).catch(err => {
            this.$notify({
              title: '失败',
              message: err,
              type: 'success',
              duration: 2000
            })
            this.loading = false
          })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消修改'
        })
      })
    },
    close() {
      // this.ps_product_id = ''
      // this.local_id = ''
      // this.showinfo = "display:none;"
      this.$emit('closeMyDialog', false)
    }
  }
}
</script>

<style scoped>

  .top >>> .input-with-select .el-input-group__prepend {
    background-color: #fff;
  }

  .input-with-select {
    width: calc(100% - 200px);
  }

  .app-container >>> .el-dialog {
    margin-top: 48px !important;
    margin-bottom: 5px;
  }

  .mt-dialog >>> .el-transfer-panel {
    width: calc(50% - 60px);
  }

  .mt-form >>> .el-select {
    width: 100%;
  }

  .mt-form >>> .el-input__inner {
    width: 100%;
  }

  .mt-dialog >>> .el-dialog {
    margin: 10px auto !important;
  }

  .mt-dialog >>> .el-dialog__body {
    padding-bottom: 60px;
    padding-top: 5px;
  }

  .top >>> .el-select {
    width: 300px;
  }
</style>
